import {getMeta ,updateMeta} from '../../../../api/member';
import { invoice } from '../../../../api/order';

Page({
    data: {
        option:{
            billingType: "0",  //类型(0.公司,1.个人 
            billingCode: "",
            billingName: "",
        },
        orderForm:{},
        applyFlage: false  //没开票
    },
    onLoad: function (options) {        
        this.data.orderForm = JSON.parse( decodeURIComponent(options.orderForm))
        this.setData({
            orderForm:this.data.orderForm
        })
    },
    onShow(){
        this.getMeta()
    },
    getMeta(){
        let params = {
            memberId: this.data.orderForm.memberId
        }
        getMeta(params).then(res=>{
            if(res.data != undefined){
                this.data.option =  res.data
                this.data.applyFlage = true
                this.setData({
                    option: this.data.option,
                    applyFlage:this.data.applyFlage
                })
            }
        })
    },
    billingTypeChoose(e){
        this.data.option.billingType = e.currentTarget.dataset.index
        this.setData({
            option:this.data.option
        })
     },
     billingNameChange(e){
        this.data.option.billingName = e.detail.value
        this.setData({
            option:this.data.option
        })
     },
     billingCodeChange(e){
        this.data.option.billingCode = e.detail.value
        this.setData({
            option:this.data.option
        })
     },
     save(){
         let params = {
            billingType:this.data.option.billingType,
            billingName:this.data.option.billingName,
            billingCode:this.data.option.billingCode,
            memberId:this.data.orderForm.memberId
         } 
        updateMeta(params).then(res=>{
            let params ={
                orderId:this.data.orderForm.id
            }
            invoice(params).then(res=>{
                wx.navigateBack({
                    delta: 1
                  })
            })
        })

     }
});